package edu.gatech.cs2340.tigershroud;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

/**
 * Handles customized ItemizedOverlay items
 * @author 
 *
 */

public class MyOverlays extends ItemizedOverlay {
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;
/**
 * Constructor for an ItemizedOverlay 
 * @param defaultMarker the icon to represent OverlayItems
 * @param context provided by the application
 */
	public MyOverlays(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context;
	}
/**
 * Adds an OverlayItem to the global mOverlays 
 * @param overlay
 */
	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	/**
	 * @param int i the index of the created item
	 */
	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}
/**An accessor for the size of mOverlays, the ArrayList containing all of the OverlayItems
 * @return an int representing the size of mOverlays
 */
	@Override
	public int size() {
		return mOverlays.size();
	}
/**
 * Determines the default behavior of an OverlayItem when the user taps it
 * @param index the the index of the item that was tapped
 * @return a boolean representing whether the item was tapped or not
 */
	@Override
	protected boolean onTap(int index) {
		OverlayItem item = mOverlays.get(index);
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		dialog.setTitle(item.getTitle());
		dialog.setMessage(item.getSnippet());
		dialog.show();
		return true;
	}
}
